/* eslint-disable indent */
'use strict'

/**
 * 下机记录息表
 */

module.exports = app => {
    const { TEXT, STRING, INTEGER, DATE, JSON } = app.Sequelize

    const DownMachineRecord = app.model.define('downmachine_record', {
        id: {
            type: INTEGER,
            primaryKey: true,
            autoIncrement: true
        },
        m_bid: {
            type: INTEGER,
            allowNull: false,
            comment: '会员绑定ID'
        },
        pid: {
            type: INTEGER,
            allowNull: false,
            comment: '门店ID'
        },
        upmachine_time: {
            type: DATE,
            allowNull: false,
            comment: '上机时间'
        },
        downmachine_time: {
            type: DATE,
            allowNull: false,
            comment: '下机时间'
        },
        consume_amount: {
            type: INTEGER,
            allowNull: false,
            comment: '消费金额'
        },
        computer_name: {
            type: STRING(255),
            allowNull: true,
            comment: '计算机名称'
        },
        area_name: {
            type: STRING(255),
            allowNull: true,
            comment: '区域名称'
        }
    })


    // 建立关联关系
    DownMachineRecord.associate = async () => {
        DownMachineRecord.belongsTo(app.model.Place, {
            onDelete: 'RESTRICT',
            onUpdate: 'CASCADE',
            foreignKey: 'pid', // 源模型中的外键信息
            // as: 'place', // 添加到源模型中的目标模型别名
            targetKey: 'id' // 目标模型中的关联字段
        })
        DownMachineRecord.belongsTo(app.model.Member, {
            onDelete: 'RESTRICT',
            onUpdate: 'CASCADE',
            foreignKey: 'm_bid', // 源模型中的外键信息
            // as: 'member', // 添加到源模型中的目标模型别名
            targetKey: 'id' // 目标模型中的关联字段
        })
    }


    return DownMachineRecord
}
